package com.lack.interfaceapitest.controller;


import com.lack.openApiClientSdk.model.User;
import com.lack.openApiClientSdk.utils.SignUtil;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/name")
public class UserController {

    @GetMapping("/get")
    public String getNameByGet(String name) {
        return "你的名字是" + name;
    }

    @PostMapping("/post")
    public String getNameByPost(@RequestParam String name) {
        return "你的名字是" + name;
    }

    @PostMapping("/json")
    public String getNameByPostJson(@RequestBody User user, HttpServletRequest request) {
//        String accessKey = request.getHeader("accessKey");
//        String secretKey = request.getHeader("secretKey");
//        String body = request.getHeader("body");
//        String nonce = request.getHeader("nonce");
//        String timeStamp = request.getHeader("timeStamp");
//        String sign = request.getHeader("sign");
//        if (!accessKey.equals("lack")) {
//            throw new RuntimeException("权限不足");
//        }
//        if (nonce.length() > 5) {
//            throw new RuntimeException("nonce长度超过限制");
//        }
//        Long currentTimeMillis = System.currentTimeMillis();
//        final Long time = 60 * 5L;
//        if (currentTimeMillis - Long.parseLong(timeStamp) > time) {
//            throw new RuntimeException("请求时间过长");
//        }
//        String genSign = SignUtil.genSign(body, "lack1");
//        if (!sign.equals(genSign)) {
//            throw new RuntimeException("签名验证失败");
//        }
        return "POST: 你的名字是" + user.getName();
    }
}
